﻿using System;
using System.Windows.Forms;

namespace BingSpatialDataServiceExcelAddin.Views
{
    public partial class InputBox : Form
    {
        public Action<DialogResult, string> Closing;

        #region Constructor

        public InputBox()
        {
            InitializeComponent();

            MessageLbl.Text = "";
        }

        #endregion

        #region Button Handlers

        private void OkBtn_Click(object sender, EventArgs e)
        {
            if (Closing != null)
            {
                Closing(DialogResult.OK, InputTbx.Text);
            }

            this.Close();
        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            if (Closing != null)
            {
                Closing(DialogResult.Cancel, null);
            }

            this.Close();
        }

        #endregion

        #region Public Methods

        public void Show(string message)
        {
            MessageLbl.Text = message;

            NativeWindow xlMain = new NativeWindow();
            xlMain.AssignHandle(new IntPtr(Globals.ThisAddIn.Application.Hwnd));

            this.ShowDialog(xlMain);
            xlMain.ReleaseHandle();
        }

        #endregion
    }
}
